#!/bin/bash
#
# 'source' this file to set the library path for the custom built OpenSSL library rather than the 
# system provided one.
#



check_rt_env() 
{

HOMELIB=~/lib
SUBDIR=$HOMELIB/rel
if [ $1 -eq 1 ]
then
   SUBDIR=$HOMELIB/debug
fi



if [ ! -f $SUBDIR/libcrypto_m.so ]
then
   echo libcrypto_m.so not found at $SUBDIR
   return 1
fi

if [ ! -f $SUBDIR/libssl_m.so ]
then
   echo libssl_m.so not found at $SUBDIR
   return 1
fi

if [ ! -f $SUBDIR/libz.so ]
then
   echo libz.so not found at $SUBDIR
   return 1
fi

return 0
}

set_rt_env()
{

if [ $1 -eq 0 ]
then
   export LD_LIBRARY_PATH=~/lib/rel:$LD_LIBRARY_PATH
else
   export LD_LIBRARY_PATH=~/lib/debug:$LD_LIBRARY_PATH
fi

}

if [ $# -lt 1 ]
then
   echo "Usage: source linux_rt_env.sh [rel|debug]" 
else
   USE_DEBUG_LIBRARIES=0
   if [ "$1" == "debug" ]
   then
      USE_DEBUG_LIBRARIES=1
   fi

   check_rt_env $USE_DEBUG_LIBRARIES
   return_value=$?
   if [ "$return_value" -eq "0" ]
   then
      set_rt_env $USE_DEBUG_LIBRARIES
   fi

fi

